<template>
  <div class="app-container">
    <el-row :gutter="10">
      <el-col :span="7" :xs="19">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="text-center">
              <userAvatar :user="user" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="user" />姓名
                <div class="pull-right">{{ user.nickName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="email" />教工号
                <div class="pull-right">{{ user.jsNumber }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="email" />学院
                <div class="pull-right" v-if="user">{{ user.xyName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" />手机号
                <div class="pull-right" >{{ user.phonenumber }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="peoples" />性别
                <div class="pull-right">{{ getFormattedSex(user.sex) }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="peoples" />角色
                <div class="pull-right" >{{ roleGroup }}</div>
              </li>
              <!-- <li class="list-group-item">
                <svg-icon icon-class="peoples" />职位
                <div class="pull-right">{{ user.zwName }}</div>
              </li> -->
              <li class="list-group-item">
                <svg-icon icon-class="tree" />状态
                <div class="pull-right" >{{getFormattedStatus(user.status)}}</div>
              </li>

<!--              <li class="list-group-item">-->
<!--                <svg-icon icon-class="tree" />-->
<!--                <div class="pull-right" v-if="user.dept">{{ user.dept.deptName }}</div>-->
<!--              </li>-->
<!--              <li class="list-group-item">-->
<!--                <svg-icon icon-class="peoples" />学院-->
<!--                <div class="pull-right">{{ user.xyName }}</div>-->
<!--              </li>-->
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="17" :xs="240">
        <el-card>
          <div slot="header" class="clearfix">
            <span>修改密码</span>
          </div>
          <el-tabs v-model="activeTab">
<!--            <el-tab-pane label="基本资料" name="userinfo">-->
<!--              <userInfo :user="user" />-->
<!--            </el-tab-pane>-->
<!--            <el-tab-pane label="" name="resetPwd">-->
              <resetPwd />
<!--            </el-tab-pane>-->
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import { getUserProfile } from "@/api/system/user";

export default {
  name: "Profile",
  components: { userAvatar, userInfo, resetPwd },
  data() {
    return {
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "resetPwd",
      fielHttp: process.env.VUE_APP_BASE_FILE, // 图片前缀
    };
  },
  created() {
    this.getUser();
  },
  methods: {

    getFormattedSex(sex) {
      const sexMap = { 0: '男', 1: '女' };
      return sexMap[sex] || '未知'; // 如果sex不是1或2，显示'未知'
    },

    getFormattedStatus(number) {
      const statusMap = { 0: '正常', 1: '停用' };
      return statusMap[number] || '未知'; // 如果sex不是1或2，显示'未知'
    },

    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        console.log(this.user);
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
      });
    }
  }
};
</script>
